Java Performance by Scott Oaks
Author:Scott Oaks
Language: eng
Format: epub
Publisher: O'Reilly Media
Published: 2019-07-31T16:00:00+00:00
Lazy Initialization Runtime Performance
The usual performance penalty for checking whether lazily initialized variables have been initialized may not always exist. Consider this example from the JDK’s ArrayList class. That class maintains an array of the elements it stores, and in older versions of Java, pseudocode for the class looked like this:
public class ArrayList { private Object[] elementData = new Object[16]; int index = 0; public void add(Object o) { ensureCapacity(); elementData[index++] = o; } private void ensureCapacity() { if (index == elementData.length) { ...reallocate array and copy old data in... } } }
A few years ago, this class was changed so that the elementData array is initialized lazily. But because the ensureCapacity() method already needed to check the array size, the common methods of the class didn’t suffer a performance penalty: the code to check for initialization is the same as the code to check whether the array size needs to be increased. The new code uses a static, shared, zero-length array so that performance is the same:
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Implementing Enterprise Observability for Success by Manisha Agrawal and Karun Krishnannair(7031)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6385)
Supercharging Productivity with Trello by Brittany Joiner(6298)
Mastering Tableau 2023 - Fourth Edition by Marleen Meier(6054)
Inkscape by Example by István Szép(5891)
Visualize Complex Processes with Microsoft Visio by David J Parker & Šenaj Lelić(5599)
Build Stunning Real-time VFX with Unreal Engine 5 by Hrishikesh Andurlekar(4586)
Design Made Easy with Inkscape by Christopher Rogers(4429)
Customizing Microsoft Teams by Gopi Kondameda(3973)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3913)
Extending Microsoft Power Apps with Power Apps Component Framework by Danish Naglekar(3571)
Salesforce Platform Enterprise Architecture - Fourth Edition by Andrew Fawcett(3426)
Pandas Cookbook by Theodore Petrou(3424)
Business Intelligence Career Master Plan by Eduardo Chavez & Danny Moncada(3366)
The Tableau Workshop by Sumit Gupta Sylvester Pinto Shweta Sankhe-Savale JC Gillet and Kenneth Michael Cherven(3231)
TCP IP by Todd Lammle(2965)
Drawing Shortcuts: Developing Quick Drawing Skills Using Today's Technology by Leggitt Jim(2893)
Applied Predictive Modeling by Max Kuhn & Kjell Johnson(2839)
Work Smarter with Microsoft OneNote by Connie Clark(2838)
